<?php namespace Admin\Controller;
class BrandController extends CommonController{
	private $model;
	public function __auto(){
	    $this->model=new \Common\Model\Brand;
	}
	
	//显示所有的品牌
	public function index(){
		$BrandImage=$this->model->orderBy('sort','ASC')->get();
		View::with('BrandImage',$BrandImage);
	 	View::make();   
	}
	//添加品牌
	public function add(){
		if(IS_POST){
			if($this->model->store()) View::success('添加成功');
			View::error($this->model->getError());
		}
		
	    View::make();
	}
	//删除
	public function del(){
	    $tid=Q("get.bid",0,'intval');
		$this->model->where("bid={$tid}")->delete();
		View::success('删除成功');
	}
	//编辑
	public function edit(){
		$bid=Q("get.bid",0,'intval');
		if(IS_POST){
			//提交修改
//			p(Q("post."));
//			exit;
			if($this->model->edit()) View::success('修改成功',U('index'));
			View::error($this->model->getError());
		}
		//获得旧数据
		$oldBrand=$this->model->where("bid={$bid}")->find();
		View::with('oldBrand',$oldBrand);
		View::make();
	}
	
}































